; (function ($) {
    "use strict";
    // message:' 操作成功',    //提示信息
    // duration:'5000',       //显示时间（默认：5s）
    // type:'info',           //显示类型，包括4种：success.error,info,warning 默认info
    // showClose:false,       //显示关闭按钮（默认：否）
    // center:true,           //页面竖直居中（默认：否）
    // onClose:function,      //点击关闭回调函数
    $.message = function (ops) {
 
        let  { 
			message, 
			duration,
			type, 
			showClose, 
			center, 
			onClose 
			} = ops;
        type = type || 'info';
        showClose = showClose === true ? showClose : false;
        center = center === true ? center : false;
        if(duration === 0){
            duration = 0;
        }else{
            duration = duration || 5000;
        }
 
        let color = {};
		
        if(type === 'info'){ 
			color = { 
				clo: '#edf3fd'
				} 
			};
        if(type === 'success'){
			color = {
				clo: '#eff7ea'
				}
			};
        if(type === 'warning'){
			color = {
				clo: '#fef6ea'
				}
			};
        if(type === 'error'){
			color = {
				clo: '#fff2f0'
				}
			};
 
        let msgTop = center === true ? $(window).height() / 2 - 200 : 10;
 
        if ($('.message')) {
            $('.message').remove();
        }
 
        $('body').append($(`<div class="message">${message}</div>`));
 
        if (showClose === true) {
            $('.message').append($('<p class = "sc">x</p>'))
            $('.sc').css({
                position: 'absolute',
                width: 16,
                height: 16,
				fontSize:18,
				lineHeight:1,
                right: 20,
                top: 0,
                bottom: 0,
                margin: 'auto 0',
                color: '#000'
            });
			// $('.sc').on('click',function(){
			// 	$('.message').remove();
			// })
        }
		
		
        $('.message').css({
            border: '1px solid #ddd',
            background: color.clo,
            position: 'absolute',
            width: 300,
            height: 50,
			fontSize:20,
			borderRadius:5,
			lineHeight:2.5,
            left: 0,
            right: 0,
            top: msgTop,
            margin: '0 auto',
        }).delay(duration).hide(0);
 
        $('.sc').on('click', function () {
            onClose ? onClose() : null;
            $('.message').hide();
        });
    }
})(jQuery);

